﻿using System;

namespace UniRx.Operators
{
	// Token: 0x02000294 RID: 660
	internal class DoObserverObservable<T> : OperatorObservableBase<T>
	{
		// Token: 0x06000EA1 RID: 3745 RVA: 0x00044DC8 File Offset: 0x000431C8
		public DoObserverObservable(IObservable<T> source, IObserver<T> observer) : base(source.IsRequiredSubscribeOnCurrentThread<T>())
		{
			this.source = source;
			this.observer = observer;
		}

		// Token: 0x06000EA2 RID: 3746 RVA: 0x00044DE4 File Offset: 0x000431E4
		protected override IDisposable SubscribeCore(IObserver<T> observer, IDisposable cancel)
		{
			return new DoObserverObservable<T>.Do(this, observer, cancel).Run();
		}

		// Token: 0x04000880 RID: 2176
		private readonly IObservable<T> source;

		// Token: 0x04000881 RID: 2177
		private readonly IObserver<T> observer;

		// Token: 0x02000295 RID: 661
		private class Do : OperatorObserverBase<T, T>
		{
			// Token: 0x06000EA3 RID: 3747 RVA: 0x00044DF3 File Offset: 0x000431F3
			public Do(DoObserverObservable<T> parent, IObserver<T> observer, IDisposable cancel) : base(observer, cancel)
			{
				this.parent = parent;
			}

			// Token: 0x06000EA4 RID: 3748 RVA: 0x00044E04 File Offset: 0x00043204
			public IDisposable Run()
			{
				return this.parent.source.Subscribe(this);
			}

			// Token: 0x06000EA5 RID: 3749 RVA: 0x00044E18 File Offset: 0x00043218
			public override void OnNext(T value)
			{
				try
				{
					this.parent.observer.OnNext(value);
				}
				catch (Exception error)
				{
					try
					{
						this.observer.OnError(error);
					}
					finally
					{
						base.Dispose();
					}
					return;
				}
				this.observer.OnNext(value);
			}

			// Token: 0x06000EA6 RID: 3750 RVA: 0x00044E88 File Offset: 0x00043288
			public override void OnError(Exception error)
			{
				try
				{
					this.parent.observer.OnError(error);
				}
				catch (Exception error2)
				{
					try
					{
						this.observer.OnError(error2);
					}
					finally
					{
						base.Dispose();
					}
					return;
				}
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x06000EA7 RID: 3751 RVA: 0x00044F10 File Offset: 0x00043310
			public override void OnCompleted()
			{
				try
				{
					this.parent.observer.OnCompleted();
				}
				catch (Exception error)
				{
					try
					{
						this.observer.OnError(error);
					}
					finally
					{
						base.Dispose();
					}
					return;
				}
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x04000882 RID: 2178
			private readonly DoObserverObservable<T> parent;
		}
	}
}
